<template>
  <div>
    <el-dialog
      title="诊断疾病"
      :visible.sync="dialogVisible"
      append-to-body
      width="50%"
      class="dialog"
      element-loading-background="rgba(0, 0, 0, 0.8)"
      :before-close="handleClose"
      :close-on-click-modal="false"
      center
    >
      <el-input
        @input="handleInputClick"
        placeholder="请输入关键字进行搜索"
        v-model="searchWord"
        class="input-with-select"
        style="margin-bottom: 10px"
      >
        <el-button
          slot="append"
          @click="handleInputClick"
          icon="el-icon-search"
        ></el-button>
      </el-input>
      <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
        <el-tab-pane label="中医病种" name="first"> </el-tab-pane>
        <el-tab-pane label="西医病种" name="second"> </el-tab-pane>
      </el-tabs>
      <el-table
        @row-click="handleSelectionChange"
        :data="tableData"
        border
        v-loading="tabloading"
        style="width: 100%"
        height="40vh"
      >
        <el-table-column prop="ICDCode" align="center" label="疾病编码">
        </el-table-column>
        <el-table-column prop="ICDName" align="center" label="疾病名称">
        </el-table-column>
      </el-table>
      <div class="flex-align-center mt15">
        <div>已选疾病：</div>
        <div style="flex: 1" v-if="selectArr.length > 0">
          <el-tag
            style="margin-left: 5px"
            v-for="tag in selectArr"
            :key="tag"
            closable
            type="success"
            @close="handleTagClose(tag)"
          >
            {{ tag }}
          </el-tag>
        </div>
        <div v-else>暂无数据</div>
      </div>
      <div slot="footer">
        <el-button type="primary" @click="submitForm('ruleForm')"
          >确认</el-button
        >
        <el-button @click="handleClose('ruleForm')">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  ApigetICDData,
  ApigetICDDataCN,
  ApiGetDepartmentDoctorList,
  ApiPostOrderChangeDoctor,
} from "../../../api/index";
export default {
  name: "prescribing",
  data() {
    return {
      tabloading: false,
      searchWord: "",
      tableData: [],
      tableDataCN: [],
      activeName: "first",
      selectArr: [],
      selectArr1: [],
      dialogVisible: false,
      ruleForm: {
        ICD: "",
        ICD1: "",
        type: "",
        main: "",
        prescribeMedicine: "",
      },
      defaultProps: {
        children: "doctors",
        label: "name",
      },
      doctorList: [],
      nodeObj: {},
    };
  },
  methods: {
    handleInputClick() {
      if (this.activeName == "first") {
        this.getICDData(this.searchWord);
      } else {
        this.getICDDataCN(this.searchWord);
      }
    },
    //选中的列表

    show() {
      this.dialogVisible = true;
      this.selectArr = [];
      this.getICDData();
    },
    getICDData(ICDName) {
      this.tabloading = true;
      ApigetICDData({ page: 1, size: 500, ICDName }).then((res) => {
        this.tabloading = false;
        this.tableData = res.data;
      });
    },
    getICDDataCN(ICDName) {
      this.tabloading = true;
      ApigetICDDataCN({ page: 1, size: 500, ICDName }).then((res) => {
        this.tabloading = false;
        this.tableData = res.data;
      });
    },

    handleClick(tab, event) {
      if (tab.index == "0") {
        this.getICDData();
      } else {
        this.getICDDataCN();
      }
    },

    handleTagClose(e) {
      if (e) {
        let index = this.selectArr.findIndex((item) => {
          return item == e;
        });
        this.selectArr.splice(index, 1);
      }
    },
    //导入患者描述信息
    /*  importPatientInfo() {
 
     } */

    handleClose() {
      this.dialogVisible = false;
    },

    handleSelectionChange(val) {
      let index = this.selectArr.find((item) => {
        return item == val.ICDName;
      });
      if (!index) {
        this.selectArr.push(val.ICDName);
        this.selectArr1.push(val.ICDCode);
      }
    },

    submitForm() {
      this.handleClose();
      this.$emit("submit", this.selectArr, this.selectArr1);
    },
    //开药
  },
};
</script>

<style>
</style>